package com.huawang.mdesign.model.service.controller;

import com.huawang.mdesign.model.service.dto.ModelLibraryDropDTO;
import com.huawang.mdesign.model.service.dto.ValidElementDTO;
import com.huawang.mdesign.model.service.dto.ValidSpecifiedRangeElementDTO;
import com.huawang.mdesign.model.service.dto.ValidationModelQueryDTO;
import com.huawang.mdesign.model.service.inter.ModelLibraryService;
import com.huawang.mdesign.model.service.inter.ValidationService;
import com.huawang.mdesign.model.service.vo.BaseResponse;
import com.huawang.mdesign.model.service.vo.ValidationModelInstanceVo;
import com.huawang.mdesign.model.service.vo.ValidatorResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "模型校验")
@RestController
@RequestMapping("/validation")
public class ValidationController {

    @Autowired
    private ValidationService validationService;

    @Autowired
    private ModelLibraryService modelLibraryService;

    @Operation(summary = "全项目校验")
    @GetMapping("/checkProject")
    public BaseResponse<List<ValidatorResultVo>> checkProject(final String projectId) {
        return BaseResponse.success(validationService.checkProject(projectId));
    }

    @Operation(summary = "模型校验")
    @PostMapping("/checkElements")
    public BaseResponse<List<ValidatorResultVo>> checkElements(@RequestBody ValidElementDTO validElementDto) {
        return BaseResponse.success(validationService.checkElements(validElementDto));
    }

    @Operation(summary = "对指定范围下的模型进行指定规则的校验")
    @PostMapping("/checkElementsByRules")
    public BaseResponse<List<ValidatorResultVo>> checkElementsByRules(@RequestBody ValidSpecifiedRangeElementDTO validElementDto) {
        return BaseResponse.success(validationService.checkElementsByRules(validElementDto));
    }


    @Operation(summary = "校验模型库构造型是否在当前项目存在")
    @PostMapping("/checkAppliedStereotype")
    public BaseResponse<Boolean> checkAppliedStereotype(@RequestBody ModelLibraryDropDTO modelLibraryDropDTO) {
        return BaseResponse.success(modelLibraryService.checkAppliedStereotype(modelLibraryDropDTO));
    }

    @Operation(summary = "查询模型校验分组")
    @GetMapping("/queryValidationGroups")
    public BaseResponse<List<ValidationModelInstanceVo>> queryValidationGroups(@RequestParam(value = "projectId") String projectId) {
        return BaseResponse.success(validationService.queryValidationGroups(projectId));
    }

    @Operation(summary = "查询模型校验分组及其下面的校验规则模型")
    @GetMapping("/queryValidationModelsOfValidationGroup")
    public BaseResponse<List<ValidationModelInstanceVo>> queryValidationModelsOfValidationGroup(@RequestParam(value = "projectId") String projectId,
                                                                                                @RequestParam(value = "validationGroupInstanceId") String validationGroupInstanceId) {
        return BaseResponse.success(validationService.queryValidationModelsOfValidationGroup(projectId, validationGroupInstanceId));
    }

    @Operation(summary = "查询校验分组校验规则树")
    @GetMapping("/queryValidationModelTree")
    public BaseResponse<ValidationModelInstanceVo> queryValidationModelTree(@RequestParam(value = "projectId") String projectId) {
        return BaseResponse.success(validationService.queryValidationModelTree(projectId));
    }

    @Operation(summary = "查询校验规则id")
    @PostMapping("/queryValidationRuleInstanceIds")
    public BaseResponse<List<String>> queryValidationRuleInstanceIds(@RequestBody ValidationModelQueryDTO queryDTO) {
        return BaseResponse.success(validationService.queryValidationRuleInstanceIds(queryDTO));
    }


}
